home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1219 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: locutus.rchland.ibm.com!usenet
  2. From: pstaite@vnet.ibm.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Q: Please help me to write to .dat file!
  5. Date: 9 Jan 1996 22:15:43 GMT
  6. Organization: IBM OS/2 Device Driver Development  Rochester, MN
  7. Message-ID: <4cupef$nk3@locutus.rchland.ibm.com>
  8. References: <4csoob$kj@news.tcd.net>
  9. Reply-To: pstaite@vnet.ibm.com
  10. NNTP-Posting-Host: warpone.rchland.ibm.com
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <4csoob$kj@news.tcd.net>, Steve <slavis@PW1.PrairieWeb.Com> writes:
  14.  
  15. <chopped>
  16.  
  17. >cout << "Enter the question number:" << endl;
  18. >cpaQuestion audit;
  19. >cin >> audit.questionNum;
  20.  
  21. When you extract a numeric from the input stream it'll stop pulling 
  22. chars from the stream at the next non-numeric.  In this case, probably 
  23. leaves the newline in the input buffer. (eg. you type '1' and Enter -- 
  24. pulls '1' out, leaves a '\n' in cin)
  25.  
  26. >if(audit.questionNum > 0 && audit.questionNum <= 100) {
  27. >        cout << "Enter answer:" <<endl;
  28. >        cin.getline(audit.answer, 3);
  29.  
  30. This getline() sees an immediate newline in the input buffer so it 
  31. returns (empty).
  32.  
  33. Try adding:
  34.  
  35. cin.ignore( 100, '\n' );
  36.  
  37. After reading numerics.  This pulls any remaining chars out up to and 
  38. including the newline, or 100 chars.
  39.  
  40.  
  41. Phil Staite, team OS/2
  42. internet: pstaite@vnet.ibm.com  internal: pstaite@rchland
  43.  
  44.